<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
    <style type="text/css">
*{margin: 0;padding: 0;list-style: none}
#div1{width: 100px;height: 100px;background: black;position: absolute;}

    </style>
</head>
<body>
<div id='div1'></div>
<script type="text/javascript">
	div1.style.left = 500+'px';
	div1.style.top = 400+'px'
	onresize= function(){
		if(innerWidth<div1.offsetLeft+div1.offsetWidth){
			div1.style.left = innerWidth-div1.offsetWidth +'px'
		}
		//console.log(1);
		//div1.style.left = innerWidth-div1.offsetWidth +'px';

		console.log('浏览器的高度:'+innerHeight+'\ndiv1的高度:'+div1.offsetHeight+'\ndiv1的top值'+div1.offsetTop)
		if(innerHeight<div1.offsetTop+div1.offsetHeight){
			div1.style.top = innerHeight-div1.offsetHeight +'px'
		}
	}

</script>
</body>
</html>